package com.zzyy.study.controller;

import cn.hutool.core.util.IdUtil;
import com.zzyy.study.annotations.CustomerLogAnnotation;
import com.zzyy.study.resp.ResultData;
import com.zzyy.study.resp.ReturnCodeEnum;
import jakarta.annotation.Resource;
import lombok.Value;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

/**
 * @auther zzyy
 * @create 2025-01-20 10:55
 */
@RestController
@Slf4j
public class CustomerController
{

    @Resource
    private ThreadPoolTaskExecutor threadPoolTaskExecutor;

    @GetMapping(value = "/customer/m1")
    public String m1()
    {
        String result = "";

        long startTime = System.currentTimeMillis();
        System.out.println("----方法前，come in");

        //主业务逻辑
        result = IdUtil.simpleUUID();
        System.out.println("----主业务逻辑订单编号: "+result);
        //暂停毫秒
        try { TimeUnit.MILLISECONDS.sleep(10); } catch (InterruptedException e) { e.printStackTrace(); }
        //主业务逻辑end

        System.out.println("----方法后，leave out");
        long endTime = System.currentTimeMillis();
        System.out.println("----costTime: "+(endTime - startTime) +" 毫秒");


        return result;
    }

    @GetMapping(value = "/customer/m2")
    @CustomerLogAnnotation(value = "java0923 yyds",enable = true)
    public String m2()
    {
        String result = "";

        result = IdUtil.simpleUUID();
        System.out.println("----主业务逻辑订单编号: "+result);

        return result;
    }

    @GetMapping(value = "/customer/m3")
    @CustomerLogAnnotation(value = "m3++",enable = false)
    public String m3()
    {
        String result = "";

        result = IdUtil.simpleUUID();
        System.out.println("----主业务逻辑订单编号m3: "+result);

        return result;
    }


    @GetMapping(value = "/customer/m4")
    public ResultData<String> m4()
    {
        System.out.println("---come in m4");

        try
        {
            System.out.println("---m4 task over");
            int age = 10/0; //故意bug
        }catch (Exception e){
            e.printStackTrace();
            return ResultData.fail(ReturnCodeEnum.RC204.getCode(),ReturnCodeEnum.RC204.getMessage() +"\t"+e.getMessage());
        }
        return ResultData.success("0923Java good");
    }

    @GetMapping(value = "/customer/m5")
    public ResultData<Integer> m5()
    {
        System.out.println("---come in m5");

        try
        {
            System.out.println("---m5 task over" + 240923);
        }catch (Exception e){
            e.printStackTrace();
            return ResultData.fail(ReturnCodeEnum.RC999.getCode(),ReturnCodeEnum.RC999.getMessage());
        }
        return ResultData.success(240923);
    }


}
